/**
 * Created by hps on 17-4-28.
 */
public class Queue1 {
    private int maxSize;
    private long[] queArray;
    private int front;
    private int rear;

    public Queue1(int s) {
        maxSize = s + 1;
        queArray = new long[maxSize];
        front = 0;
        rear = -1;
    }

    public void insert(long value) {
        if(rear == maxSize - 1)
            rear = -1;
        queArray[++rear] = value;
    }

    public long remove() {
        long temp = queArray[front++];
        if(front == maxSize)
            front = 0;
        return temp;
    }

    public long peek() {
        return queArray[front];
    }

    public boolean isEmpty() {
        return (rear + 1 == front);
    }

    public boolean isFull() {
        return (rear + 2 == front);
    }

    public int size() {
        if(rear >= front) {
            return rear - front + 1;
        } else
            return (maxSize - front) + (rear + 1);
    }
}
